#include "heightmapdialog.h"
#include "ui_heightmapdialog.h"
#include "QFileDialog"

HeightmapDialog::HeightmapDialog(QWidget *parent) :
    QDialog(parent), ui(new Ui::HeightmapDialog) {
    ui->setupUi(this);

    connect(ui->selectButton, SIGNAL(clicked()), this, SLOT(selectFile()));
    connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onAccepted()));
}

HeightmapDialog::~HeightmapDialog() {
    delete ui;
}

void HeightmapDialog::selectFile() {
    QString filename = QFileDialog::getOpenFileName(this, "Abrir Heightmap", QDir::homePath()+"/Pictures",
                                                    tr("Imagems (*.bmp;*.jpeg;*.jpg;*.png)"));
    if ( !filename.isEmpty() ) {
        this->ui->filename->setText(filename);
    }
}

void HeightmapDialog::onAccepted() {
    MainWindow *mainwindow = reinterpret_cast<MainWindow*>(this->parent());
    mainwindow->open(ui->filename->text(),
                             ui->width->value(),
                             ui->height->value(),
                             ui->orizontal->value(),
                             ui->vertical->value());
}

